export default {
  props: {
    // 类型
    type: {
      type: String,
      default: () => 'time'
    },

    // 排序
    order: {
      type: Array,
      default: () => []
    },

    // 转换格式
    format: {
      type: String,
      default: () => 'YYYY-MM-DD'
    }
  },

  data() {
    return {
      minDate: new Date(1946, 0, 0)
    };
  },

  watch: {
    value: {
      immediate: true,
      handler(val) {
        this.pickerVal = new Date();
        if (val) {
          if (!this.isValidDate(val)) {
            return this.pickerVal;
          }
          this.handlerDateTime(val);
          this.pickerVal = new Date(val);
        }
      }
    }
  },

  methods: {
    isValidDate(date) {
      return date instanceof Date && !(Number.isNaN(date.valueOf()));
    },

    // handlerDateTime
    handlerDateTime(val) {
      const format = this.$dayjs(val).format(this.format);
      // this.pickerVal

      this.handlerConfirm({
        field_value: format,
        field_label: format
      });
    }
  }
};
